package JZ;

/**
 * @Classname JZ572
 * @Description // https://leetcode-cn.com/problems/subtree-of-another-tree/comments/ 树 经典  对比 JZ26 ，两题并不相同
 * // https://leetcode-cn.com/problems/check-subtree-lcci/submissions/
 * @Date 2021/4/21 15:53
 * @Created by yin
 */
public class JZ572 {
    public boolean isSubtree(TreeNode s, TreeNode t) {
        if (s == null || t == null) return false;
        return dps(s, t) || isSubtree(s.left, t) || isSubtree(s.right, t);
    }

    public boolean dps(TreeNode s, TreeNode t) {
        if (s == null && t == null) return true;
        if (s == null || t == null || s.val != t.val) return false;
        return dps(s.left, t.left) && dps(s.right, t.right);
    }
}
